<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
<script type="text/javascript">
	
	let arr = [1, 2, 3, 4, 5, 6]
	let sum = 0

    for(let i = 0;i < arr.length; i++){
    	sum += arr[i]
    }
    console.log(sum)


    // forEach()遍历
    // arr.forEach()
    let add = 0
    arr.forEach(function(value,index,array){
    	/*
			value,index,array
			value:数组的每一项的值
			index:每一项下标
			array:原数组
    	*/
    	console.log("value:",value,"index:",index, "原数组",array)
    	add += value
    })
    console.log(add)
    var arr2 = [3, 4, 6, 11, 35, 20, 16]
    //max
    let max = arr[0]
  
    arr2.forEach(function(value){
    	if(max < value){
    		max = value	
    	}
    })
    console.log(max)
     arr2.forEach(function(value, index){
     	let temp = 0
    	if(max == value){
    		temp = arr2[index]
    		arr2[index] = arr2[arr2.length -1]  
    		arr2[arr2.length -1] = temp  
    	}
    })

</script>
</body>
</html>